/**
 * 规格化小数位数
 * @param num 数字
 * @param FIX 保留位数
 * @return {string|null} 规格化后的数字
 */
export const formatNum = (num, FIX = 2) => {
  const t = Math.pow(10, 2);
  return isNaN(num) ? null : Math.round(num * t) / t + "";
};

/**
 * 检查密码格式是否合法
 *
 * @param pwd {string} 要检查格式的密码
 * @return {boolean} true-格式规范, false-格式不规范
 */
export const checkPwdFormat = (pwd) => {
  if (pwd.length < 6 || pwd.length > 10) return false;
  let [num, upper, lower] = [0, 0, 0];
  for (const c of pwd) {
    num += isNum(c) ? 1 : 0;
    upper += isUpper(c) ? 1 : 0;
    lower += isLower(c) ? 1 : 0;
  }
  return num > 0 && upper > 0 && lower > 0;
};

const isNum = (c) => c >= "0" && c <= "9";

const isUpper = (c) => c >= "A" && c <= "Z";

const isLower = (c) => c >= "a" && c <= "z";
